/*
 *  Class name: Credentials.java
 *  Version: 1.0
 *  Date: 27.6.2014
 */
package cz.morosystems.personwebmanager.persistencelayer.entities.security;

import cz.morosystems.personwebmanager.persistencelayer.entities.User;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 *
 * @author Michal Ďuriš
 */
@Entity
@Table(name = "credentials")
public class Credentials implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(length = 40, nullable = false, unique = true)
    private String username;

    @Column(length = 40)
    private String password;

    @Column(length = 40)
    private String userRole;

    @OneToOne
    @JoinColumn(name = "user_id")
    private User user;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Credentials)) {
            return false;
        }
        Credentials other = (Credentials) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id
                                                      .equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "cz.morosystems.personwebmanager.persistencelayer.entities.security.Credentials[ id=" + id + " ]";
    }

}
